/* eslint-disable */
export default {
  data() {
    return {
      // 公司数据
      companyData:[
        {
          companyName: '大地公司',
          companyContact: '方经理',
          companyTel: '15000000000',
          requisitionLimit: '50000',
          restrictedType: 'XX领用类型',
          repairAssetType: 'XX维修类型',
        },
        {
          companyName: '天空公司',
          companyContact: '方经理',
          companyTel: '15000000000',
          requisitionLimit: '50000',
          restrictedType: 'XX领用类型',
          repairAssetType: 'XX维修类型',
        },
        {
          companyName: '太阳公司',
          companyContact: '方经理',
          companyTel: '15000000000',
          requisitionLimit: '50000',
          restrictedType: 'XX领用类型',
          repairAssetType: 'XX维修类型',
        },
        {
          companyName: '月亮公司',
          companyContact: '方经理',
          companyTel: '15000000000',
          requisitionLimit: '50000',
          restrictedType: 'XX领用类型',
          repairAssetType: 'XX维修类型',
        },
        {
          companyName: '水源公司',
          companyContact: '方经理',
          companyTel: '15000000000',
          requisitionLimit: '50000',
          restrictedType: 'XX领用类型',
          repairAssetType: 'XX维修类型',
        },
        {
          companyName: '空气公司',
          companyContact: '方经理',
          companyTel: '15000000000',
          requisitionLimit: '50000',
          restrictedType: 'XX领用类型',
          repairAssetType: 'XX维修类型',
        },
      ],

      // 新增公司弹窗
      dialogCompany:{
        title: '领用公司',
        status: false,
      },

      // 新增公司表单数据
      companyFrom:{
        companyName: '',
        companyContact: '',
        companyTel: '',
        requisitionLimit: '',
        restrictedType: '',
        repairAssetType: '',
      },

      // 新增公司表单验证
      companyRules: {
        companyName: [
          { required: true, message: '请输入公司名称', trigger: 'blur' },
        ],
        companyContact: [
          { required: true, message: '请输入联系人', trigger: 'blur' },
        ],
        companyTel: [
          { required: true, message: '请输入联系方式', trigger: 'blur' },
        ],
        requisitionLimit: [
          { required: true, message: '请输入领用限额', trigger: 'blur' },
        ],
        restrictedType: [
          { required: true, message: '请输入领用类型限定', trigger: 'blur' },
        ],
        repairAssetType: [
          { required: true, message: '请输入维修资产类型', trigger: 'blur' },
        ],
      }
    }
  },
  mounted() {

  },
  methods: {
    // 公司弹窗
    dialogCompanyOpen(row){
      console.log(row.companyName)
      if(row.companyName == undefined){
        this.dialogCompany.title = '新增公司'
        this.resetCompany()
      }else{
        this.dialogCompany.title = '更新公司'
        this.companyFrom = row
      }
      this.dialogCompany.status = true
    },

    // 新增公司
    addCompany(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$message({
            type: 'success',
            message: '新增成功!'
          })
          this.dialogCompany.status = false
        } else {
          this.$message({
            type: 'warning',
            message: '请填写相关信息!'
          })
          return false;
        }
      });
    },

    // 重置新增公司表单
    resetCompany() {
      this.companyFrom = {
        companyName: '',
        companyContact: '',
        companyTel: '',
        requisitionLimit: '',
        restrictedType: '',
        repairAssetType: '',
      }
    },

    // 删除公司
    delCompany(row){
      this.$confirm('正在删除'+  row.companyName  +'公司, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });          
      });
    },
  }
}